package com.yhl.controller;

import com.yhl.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisTxCommands;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RedisTestController {


    @Autowired
    RedisTemplate redisTemplate;
    @RequestMapping("/setStr")
    public String setStr(String value){
        redisTemplate.opsForValue().set("strKey",value);
        return "ok";
    }

    @RequestMapping("/getStr")
    public  String getStr(String key){
        return  redisTemplate.opsForValue().get(key).toString();
    }

    @RequestMapping("/setUser")
    public String setUser(){
        User user = new User();
        user.setUserName("吴京");
        user.setAddress("北京");
        user.setUserPassword("123556");
        redisTemplate.opsForValue().set("user",user);
        return "ok";
    }
    @RequestMapping("/getUser")
    public User getUser(String key){
        return (User)redisTemplate.opsForValue().get(key);
    }

    @RequestMapping("/deleteUser")
    public String deleteUser(){
        redisTemplate.delete("user");
        return "ok";
    }
}
